//
//  UserTableViewCell.swift
//  GoldStar
//
//  Created by TRS-Mobile on 2025/6/24.
//

import UIKit

class UserTableViewCell: DefaultTableViewCell {

    
    
    override func bind(to viewModel: DefaultTableViewCellViewModel) {
        super.bind(to: viewModel)
        viewModel.title
            .bind(to: titleLabel.rx.text)
            .disposed(by: cellDisposeBag)
        viewModel.date
            .map {$0.description}
            .bind(to: dateLabel.rx.text)
            .disposed(by: cellDisposeBag)
        viewModel.flowerCount
            .map { "x " + $0.description }
            .bind(to: countLabel.rx.text)
            .disposed(by: cellDisposeBag)
            
    }
    
    override func makeUI() {
        super.makeUI()
        container.addSubview(headImageView)
        headImageView.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview().inset(10)
            make.width.height.equalTo(80)
        }
        headImageView.setCornerRadius(40)
        
        container.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.right.top.equalToSuperview().inset(10)
            make.left.equalTo(headImageView.snp.right).offset(10)
        }
        
        container.addSubview(flowerImageView)
        flowerImageView.snp.makeConstraints { make in
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(5)
            make.width.height.equalTo(20)
        }
        
        container.addSubview(countLabel)
        countLabel.snp.makeConstraints { make in
            make.centerY.equalTo(flowerImageView)
            make.left.equalTo(flowerImageView.snp.right).offset(2)
        }
        
        container.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { make in
            make.left.equalTo(flowerImageView)
            make.top.equalTo(flowerImageView.snp.bottom).offset(5)
        }
    }
    
    lazy var headImageView: UIImageView = {
        let imgv = UIImageView()
        imgv.backgroundColor = .cyan
        return imgv
    }()
    
    lazy var flowerImageView: UIImageView = {
        let imgv = UIImageView(image: UIImage(named: "redFlower"))
        return imgv
    }()
    
    lazy var countLabel: UILabel = {
        let label = UILabel()
        label.font = .systemFont(ofSize: 13)
        label.textColor = .​​lakeBlue
        return label
    }()

    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .boldSystemFont(ofSize: 18)
        label.textColor = .​​lakeBlue
        return label
    }()
    
    lazy var dateLabel: UILabel = {
        let label = UILabel()
        label.font = .systemFont(ofSize: 13)
        label.textColor = .​​lakeBlue
        return label
    }()
    
}
